var vueApp = new Vue({
  el: '#app',
  data: function () {
    return {
    	  pfiles:[],
    	  pfile:'',
    	  propData:[],
    	  currentPageNbr: config.currentPageNbr,
          pageSizes: config.pageSizes,
          pageSize: config.defaultpageSize,
          totalRecords: 0,
          orgValue:'',
          showDg:false,
          form:{
        	  name:'',
        	  value:''
          }
      };
  },
  mounted: function () {
    this.initData();

  },
  methods: {
    initData:function(){
       var that = this;
       this.initFileList();
//       userEx.getUserInfo(function(data){
//            that.user_ssbm = data.userinfo.deptCode;       
//            tools.checkPriv(data.userinfo.privNames,"cbgs");         
//       });
//       tools.checkPriv(userExInfo.privNames,"cbgs"); 
       this.onSearch();
       
    },
    initFileList:function(){
    	var that = this;
        var postdata = {
        };        
        var data = tools.ajaxRequestEx("pub/prop/filelist",postdata);
        if (data.respCode == "0") {
            that.pfiles = data.list;  
            that.pfile = that.pfiles[0].label;
        }else {
            that.pfiles = [];
            that.showError(data.respDesc);     
            return false;
        }  	
    	
    },
    onSearch:function(){
    	var that = this;
        var postdata = {
      	    "fileName":  this.pfile		 
        };
        
        tools.ajaxRequestAsyncEx("pub/prop/proplist",postdata, function(data){
            if (data.respCode == "0") {
                that.propData = data.list;
                that.totalRecords =data.list.length;    
            } else {
                that.propData = [];
                that.totalRecords =0;
                that.currentPageNbr=1;
                that.showError(data.respDesc);      
            }
        });
    	
    	
    },
    delFile:function(){
    	var that= this;
    	this.$confirm('是否确认删除配置文件 '+this.pfile+' ?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
       }).then(() => {
	       	var reqData={
	       		"fileName": that.pfile  			
	   	    };
	       	tools.ajaxRequestAsyncEx("pub/prop/fileDel", reqData, function(data){
	   	   		if (data.respCode != 0) {
	   	   			that.showError(data.respDesc);    
	   	   			return false;
	   	   		}else{
	   	   			that.$message({
	   	                showClose: true,
	   	                type: 'success',
	   	                message: '删除成功!'
	   	            });  
	   	   			that.initFileList();
	   	   			that.onSearch();	
	   	   		}    	   			
	   	    });
       	
       }).catch(() => {
          		return false;
       });
    	
    },
    delProp:function(row){
    	// propSave  {fileName  operType proName  proValue}
    	var that= this;
    	this.$confirm('是否确认删除属性 '+row.name+' ?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
       }).then(() => {
	       	var reqData={
	       		"fileName": that.pfile,
	       		"operType": "del",
	       		"proName": row.name   			
	   	    };
	       	tools.ajaxRequestAsyncEx("pub/prop/propSave", reqData, function(data){
	   	   		if (data.respCode != 0) {
	   	   			that.showError(data.respDesc);    
	   	   			return false;
	   	   		}else{
	   	   			that.$message({
	   	                showClose: true,
	   	                type: 'success',
	   	                message: '删除成功!'
	   	            });  
	   	   			that.onSearch();	   	   			
	   	   		}    	   			
	   	    });
       	
       }).catch(() => {
          		return false;
       });
  	},  	
    
    newProp:function(){
    	this.form.name="";
    	this.form.value="";
    	this.showDg =true;
    	
    },  
    close:function(){
    	this.showDg =false;
    },
    padd:function(){
    	var that =this;
    	var reqData={
          "fileName": this.pfile,
          "operType": "add",
          "proName": this.form.name,
          "proValue": this.form.value
        };
        tools.ajaxRequestAsyncEx("pub/prop/propSave", reqData, function(data){
        	if (data.respCode != 0) {
    	   		that.showError(data.respDesc);    
    	   	}else{
    	   	   that.$message({
    	   	        showClose: true,
    	   	        type: 'success',
    	   	        message: '保存成功!'
    	   	   });    
    	   	   that.onSearch();
    	   	   that.close();
    		}    	   			
        });    	    	
    },
    noteval:function(row){
    	this.orgValue = row.value;
    },    
    psave: function(row){
    	var that =this;
    	if(row.value!=this.orgValue){
    		var reqData={
    	       "fileName": that.pfile,
    	       "operType": "edit",
    	       "proName": row.name,
    	       "proValue": row.value
    	    };
    	    tools.ajaxRequestAsyncEx("pub/prop/propSave", reqData, function(data){
    	   			if (data.respCode != 0) {
    	   	   			that.showError(data.respDesc);    
    	   	   			return false;
    	   	   		}else{
//    	   	   			that.$message({
//    	   	                showClose: true,
//    	   	                type: 'success',
//    	   	                message: '保存成功!'
//    	   	            });      	   	   			
    	   	   		}    	   			
    	   	});
    	}     	
    },
    closePopup: function() {
        this.$refs["btn"].click();
    },
    
    search:function(){
    	this.currentPageNbr = 1;
        this.onSearch();
    },
    handleSizeChange:function(pageSize){
        this.pageSize = pageSize;
        this.currentPageNbr = 1;
        this.onSearch();
    },

    handleCurrentChange:function(currentPageNbr){
      this.currentPageNbr = currentPageNbr;
      this.onSearch();
    },

    showError: function(info){
        var i = (info==undefined?"加载数据错误":info);
        this.$alert(i, '系统错误', {
             confirmButtonText: '确定'
        }); 
    },

  },
  watch:{
//      currentPageNbr : function() {
//          // alert(this.currentPageNbr);
//          this.onSearch();
//      },
//        
//      pageSize : function() {
//          // alert(this.currentPageNbr);
//    	  if(this.currentPageNbr=="1"){
//    		  this.onSearch();
//    	  }else{
//    		  this.currentPageNbr=="1";
//    	  }         
//      },
  }
})